package xmlMapping.lts;

import java.io.Serializable;
import java.util.*;

public class InstrumentPool implements Serializable {
    private static final long serialVersionUID = 1L;
    private String id;
    private String name;
    private String exchangeSubAccount;
    // k=Account id
    private Set<String> accounts = new HashSet<>();
    private InstrumentPoolType type;
    private String operator;
    private Date updateTime;

    public InstrumentPool() {
    }

    public InstrumentPool(String id, String exchangeSubAccount) {
        super();
        this.id = id;
        this.exchangeSubAccount = exchangeSubAccount;
    }

    public String getId() {
        return id;
    }

    public String getExchangeSubAccount() {
        return exchangeSubAccount;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setExchangeSubAccount(String exchangeSubAccount) {
        this.exchangeSubAccount = exchangeSubAccount;
    }

    public InstrumentPoolType getType() {
        return type;
    }

    public void setType(InstrumentPoolType type) {
        this.type = type;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Set<String> getAccounts() {
        return accounts;
    }

    public void setAccounts(Set<String> accounts) {
        this.accounts = accounts;
    }

    public void add(AccountPool accountPool) {
        accounts.add(accountPool.getAccount());
    }

    public void delete(AccountPool accountPool) {
        accounts.remove(accountPool.getAccount());
    }

    public List<AccountPool> encodeAccountPools() {
        List<AccountPool> accountPools = new ArrayList<>();
        for (String account : accounts) {
            accountPools.add(new AccountPool(account, this.id));
        }
        return accountPools;
    }

    @Override
    public String toString() {
        return "InstrumentPool{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", type=" + type +
                ", operator='" + operator + '\'' +
                '}';
    }
}
